package be.rivendale.renderer.mk2.local;

import be.rivendale.material.Color;
import be.rivendale.renderer.mk2.Producer;
import be.rivendale.renderer.mk2.data.Queue;
import be.rivendale.renderer.mk2.data.Rectangle;
import be.rivendale.renderer.mk2.data.Segment;

import java.util.List;

public class MultiThreadedProducer implements Producer {
    Queue<Rectangle> inputQueue = new Queue<Rectangle>();

    public MultiThreadedProducer(int numberOfRenderThreads, Queue<Segment> resultQueue) {
        System.out.println("Starting a new rendering node of " + numberOfRenderThreads + " threads.");
        for(int i = 0; i < numberOfRenderThreads; i++) {
            createRenderThread(inputQueue, resultQueue).start();
        }
    }

    protected RenderThread createRenderThread(Queue<Rectangle> inputQueue, Queue<Segment> outputQueue) {
        return new RenderThread(inputQueue, outputQueue, Color.BLACK, 0);
    }

    public void offerWork(List<Rectangle> work) {
        for (Rectangle rectangle : work) {
            inputQueue.put(rectangle);
        }
    }
}
